import request from '@/utils/request';

// 获取所有图书（分页）
export function getAllBooks(params) {
  return request({
    url: '/books',
    method: 'get',
    params
  });
}

// 根据ID获取图书
export function getBookById(id) {
  return request({
    url: `/books/${id}`,
    method: 'get'
  });
}

// 创建图书
export function createBook(data) {
  return request({
    url: '/books',
    method: 'post',
    data
  });
}

// 更新图书
export function updateBook(id, data) {
  return request({
    url: `/books/${id}`,
    method: 'put',
    data
  });
}

// 删除图书
export function deleteBook(id) {
  return request({
    url: `/books/${id}`,
    method: 'delete'
  });
}

// 根据标题搜索图书
export function searchBooks(title) {
  return request({
    url: '/books/search',
    method: 'get',
    params: { title }
  });
}

// 根据分类获取图书
export function getBooksByCategory(category) {
  return request({
    url: '/books/category',
    method: 'get',
    params: { category }
  });
}
